package sqldatabase;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * Created by Administrator on 2015/3/14.
 */
public class MangerDataBase {

    private DbOpenHelper dbOpenHelper;
    boolean flag=false;
    public MangerDataBase(Context context){
       dbOpenHelper=new DbOpenHelper(context);
    }
    public boolean insert(String table, String nullColumnHack, ContentValues values){
        SQLiteDatabase db = dbOpenHelper.getWritableDatabase();

        long id = db.insert(table, nullColumnHack, values);
        flag = (id>0?true:false);
        return flag;
    }
    public boolean update(String table, ContentValues values, String whereClause, String[] whereArgs){
        SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
        int count = db.update(table, values, whereClause, whereArgs);
        flag=(count>0?true:false);
        db.close();
        return flag;
    }
    public boolean delete(String table, String whereClause, String[] whereArgs){
        SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
        int count = db.delete(table, whereClause, whereArgs);
        flag=(count>0?true:false);
        return flag;
    }
    public Cursor select(boolean distinct, String table, String[] columns,
                         String selection, String[] selectionArgs, String groupBy,
                         String having, String orderBy, String limit){
        SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
        Cursor cursor = db.query(distinct,table,columns,selection,selectionArgs,groupBy,having,orderBy,limit);
        return cursor;
    }

}
